package com.sd.coupon.controller;

import javax.annotation.Resource;

import com.sd.coupon.entity.CategoryGoods;
import com.sd.coupon.model.res.CategoryRes;
import com.sd.coupon.service.ICategoryGoodsService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

//import com.sd.coupon.service.ICategoryGoodsService;
import com.sd.coupon.util.rest.RestResponse;

import java.util.ArrayList;
import java.util.List;

@Controller
public class CategoryController {
	
	@Resource
    ICategoryGoodsService categoryGoodsService;

	@RequestMapping(value = "/categoryList", method = RequestMethod.POST)
	@ResponseBody
	public RestResponse getCategoryList() {

		List<CategoryGoods> list = categoryGoodsService.getAll();
		List<CategoryRes> res = new ArrayList<>();
		if (list!=null && list.size()>0){
			for (CategoryGoods cate: list) {
				if(cate!=null){
					res.add(new CategoryRes(cate));
				}
			}
		}

		return RestResponse.success(res);
	}

	@RequestMapping(value = "/categoryTree", method = RequestMethod.POST)
	@ResponseBody
	public RestResponse getCategoryTree() {
		List<CategoryRes> list = categoryGoodsService.getCategoryTree();
		return RestResponse.success(list);
	}


}
